export const indent = {
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 3,
        total: 20,
      },
      state: 0,
      text: '',
      timeArr: [],
      tableData: [],
      loading:false,
    }
  },
  filters: {
    stateFilter(value) {
      if (value == 1) return "待支付";
      else if (value == 2) return "已支付";
      else if (value == 3) return "待核销";
      else if (value == 4) return "已完成";
      else return "已取消";
    }
  },
  computed: {
    starttime() {
      if (this.timeArr.length > 0) {
        return this.timeArr[0]
      } else {
        return '';
      }
    },
    endtime() {
      if (this.timeArr.length > 0) {
        return this.timeArr[1]
      } else {
        return '';
      }
    },
  },
  methods: {
    async getIndexList() {
      this.loading = true;
      let { pageNum, pageSize } = this.pageInfo;
      let { state, text, typeid, starttime, endtime } = this;
      let query = this.$QS.stringify({ pageNum, pageSize, state, text, typeid, starttime, endtime });
      let res = await this.$API.Indent.reqIndexList(query);
      if (res.code == 200) {
        this.pageInfo.total = res.data.total;
        this.tableData = res.data.list;
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
        this.$message({message: '没有数据',type: 'error'})
      }
      this.loading=false;
    },
    async getSearchIndexList() {
      this.pageInfo.pageNum = 1;
      await this.getIndexList();
      if(this.tableData.length > 0) {
        this.$message({message: '筛选成功',type: 'success'})
      }
    },
    clearSearch() {
      this.state = 0;
      this.text = '';
      this.timeArr = [];
      this.pageInfo.pageNum = 1;
      this.getIndexList();
    },
    toDetail(row){
      let {id} = row;
      this.$router.push({name:'IndentDetail', query:{id}});
    }
  },
  watch: {
    timeArr() {
      if (!this.timeArr) {
        this.timeArr = [];
      }
    },
  },
  mounted() {
    this.getIndexList()
  },
}